<template>
  <!--会签管理-我的审批-劳务结算详情弹窗-->
    <j-modal
      :title="title"
      :width="width"
      :visible="visible"
      switchFullscreen
      @ok="handleOk"
      :okButtonProps="{ class:{'jee-hidden': pageType === 'approve'?false:true} }"
      :cancelButtonProps="{ class:{'jee-hidden': pageType === 'approve'?false:true} }"
      @cancel="close"
      okText="同意">
      <template v-if="pageType === 'history'">
        <div v-if="list && list.length>0">
        <a-tabs type="card" @change="callback">
          <a-tab-pane  v-for="(item,index) in list" :key="index+1" :tab="'第'+(index+1)+'次审批'">
            <!-- <wt-xiangmuxiang-form ref="realForm2" :disabled="disableSubmit2" :defaultModel="item"></wt-xiangmuxiang-form> -->
            <wt-laowushenpi-form ref="realForm2"  :disabled="disableSubmit" :defaultModel="item"></wt-laowushenpi-form>
          </a-tab-pane>
        </a-tabs>
        </div>
        <div v-else style="height:400px">暂无审核记录</div>
      </template>
      <template v-else>
          <wt-laowushenpi-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" @handleOpen="handleOpen"></wt-laowushenpi-form>
      </template>
      <template #footer>
        <a-button v-if="!(pageType === 'approve'?false:true)" key="back" @click="handleCancel">取消</a-button>
        <a-popconfirm v-if="!(pageType === 'approve'?false:true)" title="确定驳回吗？" @confirm="handleReject"><a-button key="reject" type="primary" style="background: red;color: white;border: 1px solid red;">驳回</a-button></a-popconfirm>
        <a-popconfirm v-if="!(pageType === 'approve'?false:true)" title="确定同意吗？" @confirm="handleAgree"><a-button key="submit" type="primary">同意</a-button></a-popconfirm>
      </template>
    </j-modal>
  </template>

  <script>
    import WtLaowushenpiForm from './WtLaowushenpiForm'
    import {
      httpAction,
      getAction
    } from '@/api/manage'
    export default {
      name: 'WtyiShenpiModal',
      components: {
        WtLaowushenpiForm,
      },
      data () {
        return {
          title:'',
          width:1000,
          visible: false,
          disableSubmit: false,
          disableSubmit1: true,
          pageType: 'detail', //detail-详情 approve-审批 edit-编辑
          url: {
            detail: '/countersign/wtCountersignServiceSettlement/queryByApprovNumber',
            edit: '',
            approve: '',
            queryById: '',
          },
          list: [],
        }
      },
      methods: {
        add () {
          this.visible=true
          this.$nextTick(()=>{
            this.$refs.realForm.add();
          })
        },
        edit(record, type) {
          if (!!type) {
            this.pageType = type;
          }
          this.visible = true
          if (this.pageType === 'history') {
            this.getHistoryData(record);
          } else {
            this.$nextTick(() => {
              this.$refs.realForm.edit(record, type);
              this.disableSubmit = true;
            })
          }
          this.$forceUpdate();
        },
        //获取历史记录
        getHistoryData(record) {
          var that = this;
          getAction(`/countersign/wtCountersignServiceSettlement/queryByApprovNumber?approvNumber=${record.approvNumber}`)
            .then((res) => {
              if (res.success) {
                this.list = res.result;
              }
            })
        },
        close () {
          this.$emit('close');
          this.visible = false;
        },
        handleOk () {
          this.$refs.realForm.submitForm();
        },
        //驳回
        handleReject() {
          this.$refs.realForm.submitForm('3');
        },
        //同意
        handleAgree() {
          this.$refs.realForm.submitForm('2');
        },
        submitCallback(){
          this.$emit('ok');
          this.visible = false;
        },
        //查看原审核记录
        handleOpen(type) {
          this.$emit('handleOpen', type);
        },
        handleCancel () {
          this.close()
          // this.$refs.realForm1.edit();
        }
      }
    }
  </script>